/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmFont.h"
using namespace prs;

// TRuleFrmFont ///////////////////////////////////////////////////////////////

//
TRuleFrmFont::TRuleFrmFont(snt::text::TContext &Context,svl::TVariant &VFont) 
:vFont(VFont)
,setStyle(*this)
,RColor(Context,vColor)
{
  snt::TFVoid          F;
  snt::TReturn         Return;
  snt::text::TSequence T(Context);
  snt::text::TString   S(Context);
  snt::text::TNumber   N(Context);

  vThis = this;
  vColor = &color;

  this->Name(GetClassName())
  | T.New("font") & T.New("(") & A.New()
  //| Return.New(GetClassName())
  ;
  A.Name(GetClassName() + "[A]")
  | T.New("name")   & T.New("=") & S.New(vString) & F.New(FName  ,vThis,vString) & A.New()
  | T.New("height") & T.New("=") & N.New(vNumber) & F.New(FHeight,vThis,vNumber) & A.New()
  | T.New("style")  & T.New("=") & RStyle.New() & A.New()
  //| T.New("color")  & T.New("=") & RColor.New() & A.New()
  | RColor.New() & F.New(FColor,vThis) & A.New()
  | T.New(")") & Return.New(GetClassName() + "[A]")
  ;
/**********
  RColor.Name(GetClassName() + "[RColor]")
  | N.New(vR) & T.New(",") 
    & N.New(vG) & T.New(",") 
    & N.New(vB) & F.New(FColor,vThis,vR,vG,vB)
    & Return.New(GetClassName() + "[RColor]")
  ;
************/  

  RStyle.Name(GetClassName() + "[RStyle]")
  | AStyle1.New()
  ;
  AStyle1.Name(GetClassName() + "[AStyle1]")
  | T.New("normal",setStyle) & AStyle2.New()
  | T.New("bold",  setStyle) & AStyle2.New()
  | T.New("italic",setStyle) & AStyle2.New()
  ;
  AStyle2.Name(GetClassName() + "[AStyle2]")
  | T.New(",") & AStyle1.New()
  | Return.New(GetClassName() + "[AStyle2]")
  ;
}

//
frm::TFont &TRuleFrmFont::GetFont()
{
  frm::TFont *Font = dynamic_cast<frm::TFont*>(vFont.Pointer()); 
  
  if (!Font) { 
    Except("GetFont[!Font]");
  }
  return *Font;
}

//
void TRuleFrmFont::FColor(snt::TParams &Params) 
{ 
  TRuleFrmFont &R = GetThis(Params[0]);
  R.GetFont().Color.SetValue(R.color);
/********
  GetThis(Params[0]).GetFont().Color.SetValue(
    Params[1].Integer(),Params[2].Integer(),Params[3].Integer()
  ); 
*********/  
}

//
bool TRuleFrmFont::TSetStyle::TEvents_DoEntry(snt::text::TSequence &Sequence,svl::TString &OutError)
{
  svl::TString S = Sequence.GetSequence(); 
  frm::TFont::TStyle &Style = Rule.GetFont().Style;
  
  if (S.CompareIC("bold")) { 
    Style.AddValue(grf::TFontStyle::Bold); 
  }
  else if (S.CompareIC("italic")) { 
    Style.AddValue(grf::TFontStyle::Italic); 
  }
  else if (S.CompareIC("normal")) { 
    Style.SetNormal(); 
  }
  else { 
    Except("TEvents_DoEntry[else]"); 
  }
  return true;  
}
